import { Body, ClassSerializerInterceptor, Controller, Get, Post, Query, Req, UseGuards, UseInterceptors } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { LoginDto } from './dto/LoginDto';
import { AuthService } from './auth.service';
import { ApiTags } from '@nestjs/swagger';
import { Role, Roles } from './roles.decorator';

@ApiTags('验证')
@Controller('auth')
export class AuthController {
  constructor(
    private readonly authService: AuthService
  ) { }

  // 刷新token
  @Get('refreshToken')
  refreshToken(@Query() query: any) {
    console.log(query);
    return this.authService.refreshToken(query.refresh_token)
  }

  // 登录
  // @UseGuards(AuthGuard('local'))
  @UseInterceptors(ClassSerializerInterceptor)
  @Post('login')
  async login(@Body() user: LoginDto, @Req() req) {
    return this.authService.login(user)
  }

  @UseGuards(AuthGuard('jwt'))
  @Get()
  getUserInfo(@Req() req) {
    console.log(req);
    return req.user;
  }
  
  @Roles(Role.Admin)
  @Get("queryUserMenu")
  queryUserMenu(@Query() query) {
    return this.authService.queryUserMenu(query)
  }

}



